<template>
  <div class="box">
    <div class="box-con">
      <div class="box-left">
        <div
          @click="funxiang(group.id)"
          v-for="group in table"
          :key="group.id"
          class="datuk"
        >
          <img :src="group.titleImage" alt="" />
          <h3>{{ group.title }}</h3>
          <p>{{ group.description }}</p>
          <div class="ererk">
            <div class="yier">
              {{ group.tags[0].name }}
            </div>
          </div>
        </div>
        <div class="block">
          <span class="demonstration"></span>
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="ruleFrom.current"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="ruleFrom.size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="ruleFrom.total"
          >
          </el-pagination>
        </div>
      </div>
      <div class="right" el-icon-eleme>
        <div class="right-tou">
          <img :src="cxk.avatar" alt="" />
          <h3>{{ cxk.author }}</h3>
          <p>{{ cxk.introduction }}</p>
        </div>
        <div class="fenleik">
          <h3 style="margin-left: 10px">分类</h3>
          <div
            class="fenlei"
            @click="Fenxiang(item.id)"
            v-for="(item, index) in csshu"
            :key="index"
          >
            <div class="fen-con">
              <i class="el-icon-folder-opened"></i>
              {{ item.name }}
            </div>
          </div>
        </div>
        <div class="biaoqian">
          <h3 class="qianzi">标签</h3>
          <div style="width: 90%; margin: 0 auto">
            <div
              style="display: inline-block"
              v-for="(item, index) in biaoqian"
              :key="index"
              class="bianqianzi"
            >
              {{ item.name }}
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="box-xia">
      <div class="box-xia-com">
        <div>
          © 2023
          <span>Weblog™.</span>
          All Rights Reserved.
        </div>
        <div>Provided by <span>犬小哈</span></div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      table: [],
      cxk: {},
      ruleFrom: {
        current: 1,
        size: 10,
        total: 0,
      },
      csshu: [],
      biaoqian: [],
    };
  },
  created() {
    this.getList();
    this.getAdd();
    this.getFen();
    this.getBiao();
  },
  methods: {
    Fenxiang(id) {
      this.$router.push({
        path: "/home/fenxiang",
        query: { categoryId: id },
      });
    },
    funxiang(articleId) {
      this.$router.push({
        path: "/home/shouxiang",
        query: { articleId: articleId },
      });
    },

    async getBiao() {
      let res = await this.$axios.post(
        "http://47.104.167.34:9110/api/tag/list"
      );
      console.log(res);
      this.biaoqian = res.data.data;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.ruleFrom.size = val;
      this.getList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.ruleFrom.current = val;
      this.getList();
    },
    async getList() {
      let res = await this.$axios.post(
        "http://47.104.167.34:9110/api/index/article/list",
        {
          current: this.ruleFrom.current,
          size: this.ruleFrom.size,
        }
      );
      console.log(res);
      this.table = res.data.data;
      this.ruleFrom.total = res.data.total;
      // console.log(this.table);
    },
    async getFen() {
      let res = await this.$axios.post(
        "http://47.104.167.34:9110/api/category/list"
      );
      console.log(res);
      this.csshu = res.data.data;
    },
    async getAdd() {
      let res = await this.$axios.post(
        "http://47.104.167.34:9110/api/blog/setting/detail"
      );
      // console.log(res);
      this.cxk = res.data.data;
    },
  },
};
</script>

<style scoped>
@import "./shouye.css";
</style>